﻿using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using SharpAnalyzer.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace SharpAnalyzer.Collectors
{
    internal sealed class SimpleMemberCollectorSyntaxWalker : CSharpSyntaxWalker
    {
        private readonly List<SyntaxNode> members = new List<SyntaxNode>();

        public SimpleMemberCollectorSyntaxWalker()
          : base(SyntaxWalkerDepth.Node)
        {
        }

        public IEnumerable<SyntaxNode> GetMembers(SemanticModel semanticModel, TypeDeclarationSyntax type)
        {
            Verify.NotNull(() => type);

            Visit(type);
            return members.AsReadOnly();
        }

        public override void VisitConstructorDeclaration(ConstructorDeclarationSyntax node)
        {
            base.VisitConstructorDeclaration(node);
            members.Add(node);
        }

        public override void VisitDestructorDeclaration(DestructorDeclarationSyntax node)
        {
            base.VisitDestructorDeclaration(node);
            members.Add(node);
        }

        public override void VisitMethodDeclaration(MethodDeclarationSyntax node)
        {
            base.VisitMethodDeclaration(node);
            members.Add(node);
        }

        public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node)
        {
            base.VisitPropertyDeclaration(node);
            members.Add(node);
        }

        public override void VisitEventDeclaration(EventDeclarationSyntax node)
        {
            base.VisitEventDeclaration(node);
            members.Add(node);
        }

        public override void VisitFieldDeclaration(FieldDeclarationSyntax node)
        {
            base.VisitFieldDeclaration(node);
            members.Add(node);
        }
    }
}
